package vip.lsjscl.flowboot.util.converter;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import vip.lsjscl.flowboot.workflow.model.FlowDiagram;

/**
 * JSON 转换器
 *
 * @author zhangxingju
 * @date 2025/02/15
 */
@Converter
public class FlowDiagramConverter implements AttributeConverter<FlowDiagram, String> {

    @Override
    public String convertToDatabaseColumn(FlowDiagram attribute) {
        if (attribute == null) {
            return null;
        }
        return JSON.toJSONString(attribute);
    }

    @Override
    public FlowDiagram convertToEntityAttribute(String dbData) {
        if (dbData == null) {
            return null;
        }
        return JSONObject.parseObject(dbData, FlowDiagram.class);
    }
} 